package com.chis.shardingjdbc.config;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;

public class TzShardAlgorithm implements PreciseShardingAlgorithm<Date> {
    private static SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMM");
    
    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Date> preciseShardingValue) {
        String tableName = preciseShardingValue.getLogicTableName();
        String key = dateformat.format(preciseShardingValue.getValue());
        return tableName.concat("_").concat(key);
    }

  

}
